package com.dbappsecurity.bifrost.view;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import butterknife.BindView;
import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.dbappsecurity.bifrost.BuildConfig;
import com.dbappsecurity.bifrost.R;
import com.dbappsecurity.bifrost.base.InjectBaseActivity;
import com.dbappsecurity.core.utils.RxUtils;
import io.reactivex.Observable;
import io.reactivex.disposables.Disposable;
import java.util.concurrent.TimeUnit;

public class SplashActivity extends InjectBaseActivity {

  @BindView(R.id.txt_splash) TextView mSkip;

  int SKIP_NUM = BuildConfig.SKIP_NUM;

  @Override
  protected int getLayout() {
    return R.layout.activity_splash;
  }

  @Override
  protected void onViewCreated(Intent source, Bundle savedInstanceState) {
    super.onViewCreated(source, savedInstanceState);
    Intent intent = new Intent();
    if (BuildConfig.DEMO)
      intent.setComponent(new ComponentName(this,DemoActivity.class));
    else
      intent.setComponent(new ComponentName(this,MainActivity.class));

    Observable<Long> singleOne = Observable.just(0L);
    Observable<Long> interval = Observable.interval(0, 1, TimeUnit.SECONDS).take(SKIP_NUM);

    Disposable disposable =
        Observable.concat(singleOne, interval)
            .compose(RxUtils.rxObservableSchedulerHelper())
            .map(aLong -> SKIP_NUM - aLong)
            .doOnComplete(() -> {
              finish();
              startActivity(intent);
            })
            .subscribe(aLong -> {
              mSkip.setText(mBuilder.get().append(aLong).append("秒 跳过"));
              mBuilder.get().setLength(0);
            });
    addDisposable(disposable);

    mSkip.setOnClickListener(v -> {
      removeDisposable(disposable);
      finish();
      startActivity(intent);
    });

    //initLocationOption();
  }


}
